package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * C端购物车相关接口
 */
@Api(value = "/user/shoppingCart", tags = {"C端购物车相关接口"})
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车功能
     * @param shoppingCartDTO
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ShoppingCartDTO", name = "shoppingCartDTO", value = "", required = true)
    })
    @ApiOperation(value = "添加购物车功能", notes = "添加购物车功能", httpMethod = "POST")
    @PostMapping("/add")
    public Result save(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        return shoppingCartService.save(shoppingCartDTO);
    }

    /**
     * 获取该用户购物车中的所有信息
     * @return
     */
    @ApiOperation(value = "获取该用户购物车中的所有信息", notes = "获取该用户购物车中的所有信息", httpMethod = "GET")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list() {
        return shoppingCartService.list();
    }

    /**
     * 清空该用户购物车功能
     * @return
     */
    @ApiOperation(value = "清空该用户购物车功能", notes = "清空该用户购物车功能", httpMethod = "DELETE")
    @DeleteMapping("/clean")
    public Result clean() {
        return shoppingCartService.clean();
    }

    /**
     * 扣减购物车中商品数量功能
     * @param shoppingCartDTO
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ShoppingCartDTO", name = "shoppingCartDTO", value = "", required = true)
    })
    @ApiOperation(value = "扣减购物车中商品数量功能", notes = "扣减购物车中商品数量功能", httpMethod = "POST")
    @PostMapping("sub")
    public Result subNumber(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        return shoppingCartService.subNumber(shoppingCartDTO);
    }
}
